﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BankSite.Sites.Deposits
{
    public partial class WithdrawDeposit : System.Web.UI.Page
    {

        
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void NewDepositFormView_DataBound(object sender, EventArgs e)
        {

        }

        protected void CurrencyDropdownEDS_QueryCreated(object sender, QueryCreatedEventArgs e)
        {
            var Currencies = e.Query.Cast<Waluty>();
            e.Query = from currency in Currencies where currency.id == 120 select currency;  // jak na razie limitujemy do PLN; będzie trzeba zrobić rozliczanie międzywalutowe
        }

        protected void DepositDurationEDS_QueryCreated(object sender, QueryCreatedEventArgs e)
        {

        }

        protected void WithdrawDepositEDS_QueryCreated(object sender, QueryCreatedEventArgs e)
        {
            var Deposits = e.Query.Cast<vLokaty>();
            long clientId = -1;
            if(Int64.TryParse(Session["ClientID"] != null ? Session["ClientID"].ToString() : "", out clientId))
            {
                e.Query = from deposit in Deposits where deposit.id_klient == clientId select deposit;
            }
            
        }

        protected void WithdrawButton_Click(object sender, EventArgs e)
        {
            var varid = this.WithdrawDepositFV.DataKey.Value;
            long longid = 0;
            if(Int64.TryParse(varid.ToString(), out longid)){
                using (var context = new BankBaseEntities())
                {
                    context.WithdrawDeposit(longid);
                }
            }
        }


    }
       
}